package org.agile4j.math.recursion;

import java.util.ArrayList;

/**
 * 递归操作
 */
public class RecursionDemo01 {

    public static long[] rewards = {1, 2, 5, 10};

    /**
     * @param totalReward 赏金总金额
     * @param result
     */
    public static void get(long totalReward, ArrayList<Long> result) {
        // 当赏金 totalReward = 0时，跳出递归
        if (totalReward == 0) {
            System.out.println(result);
            return;
        }
        // 当赏金 totalReward < 0 时，不满足条件 不输出
        else if (totalReward < 0) {
            return;
        } else {
            for (int i = 0; i < rewards.length; i++) {
                ArrayList<Long> newResult = (ArrayList<Long>) result.clone();
                newResult.add(rewards[i]);
                get(totalReward - rewards[i], newResult);
            }
        }


    }

    public static void main(String[] args) {
//        ArrayList<Long> numList = new ArrayList<>();
//        numList.add(1L);
//        numList.add(2L);
//        numList.add(3L);
//        numList.add(4L);
//        ArrayList<Long> temp = (ArrayList<Long>) numList.clone();
//        numList.remove(1L);
//        System.out.println(numList);
//        System.out.println(temp);

        RecursionDemo01.get(10,new ArrayList<Long>());

    }
}
